package com.gzkemays.music.service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.IService;
import com.gzkemays.music.expcetion.MusicException;
import com.gzkemays.music.po.Music;
import com.gzkemays.music.po.vo.MusicBasicInformationVo;

import java.io.IOException;
import java.util.List;
import java.util.Objects;

/**
 * 服务类
 *
 * @author gzkemays
 * @since 2021-03-27
 */
public interface MusicService extends IService<Music> {
  default boolean validate(String fileName) {
    if (Objects.isNull(fileName)) throw new MusicException(301, "请输入文件名");
    if (Objects.nonNull(
        getBaseMapper().selectOne(Wrappers.<Music>lambdaQuery().eq(Music::getName, fileName))))
      throw new MusicException(302, "已有相同的文件名");
    return true;
  }

  // 上传文件
  Music upload(MusicBasicInformationVo vo) throws IOException;
  // 根据ID获取音频地址
  Music findUrlById(int id);
  // 获取音频列表
  List<Music> findMusicList();
}
